package com.hyfrogx.modules.manage.service.task.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hyfrogx.common.exception.ServiceException;
import com.hyfrogx.modules.manage.dao.task.TaskRewardDao;
import com.hyfrogx.modules.manage.entity.task.TaskRewardEntity;
import com.hyfrogx.modules.manage.service.task.TaskRewardService;
import com.hyfrogx.modules.manage.util.TaskRewardUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
/**
 * @author 罗春杰-技术部
 */
@Service
public class TaskRewardServiceImpl extends ServiceImpl<TaskRewardDao, TaskRewardEntity> implements TaskRewardService {
    @Override
    public List<TaskRewardEntity> findHyTaskRewardByCode(Integer code) throws ServiceException {
        // TODO Auto-generated method stub
        List<TaskRewardEntity> list = this.baseMapper.findHyTaskRewardByCode(code);
        return list;
    }
    @Override
    public TaskRewardEntity getHyTaskReward(List<TaskRewardEntity> list) {
        // 获取邀请人应赠送积分
        TaskRewardEntity hyTaskReward;
        // 看是一项奖励还是多项,该任务不存在不做处理
        if (list.size() == 1) {
            hyTaskReward = list.get(0);
        } else {
            // 往随机池里取出一项
            hyTaskReward = TaskRewardUtils.getReward(list);
        }
        return hyTaskReward;
    }

    @Override
    public TaskRewardEntity getSendScoreByMoney(BigDecimal money) {
        TaskRewardEntity sendScoreByMoney = this.baseMapper.getSendScoreByMoney(money);
        return sendScoreByMoney;
    }

}
